const express = require('express')
const logger = require('morgan');
const bodyParser = require('body-parser')
const config = require('./config');
const routes = require('../routes/index.route');
const cors = require('cors');
const passport = require('./passport')
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');

const app = express()


if (config.env === 'development') {
    app.use(logger('dev'));
}

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

// enable CORS - Cross Origin Resource Sharing
app.use(cors());

app.use(passport.initialize());

// swagger
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

// router
app.use('/api/v1', routes);
// static file in dir "uploads"
app.use('/static', express.static('uploads'))

module.exports = app;